home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / mhs_c.arc / OUTPOST.ARC / OPENFILE.C < prev    next >
C/C++ Source or Header  |  1988-06-27  |  2KB  |  78 lines

  1. /* ****************************** OPENFILE.C ****************************** */
  2. #include "cctypes.h"
  3.  
  4. extern int InFile;
  5. extern int OutFile;
  6. extern char InFileName[];
  7. extern char OutFileName[];
  8. extern char InExtension[];
  9.  
  10. int OpenInputFile() /* the file created by XRBoxOut */
  11. {
  12.     char *p;
  13.     int returnCode = NO_ERROR;
  14.  
  15.     /* check for illegal extensions */
  16.     p = strrchr(InFileName,'.');
  17.     if ( p != NULL ) {
  18.         if ( strcmp(p,InExtension) != 0 ) {
  19. /*             Error(INVALID_FILENAME); */
  20.             returnCode = -1;
  21.             goto Out;
  22.         }
  23.     }
  24.     /* open the input file (read) */
  25.     InFile = open(InFileName, O_RDONLY | O_RAW, 0);
  26.     if ( (InFile == -1) &&
  27.         (strchr(&InFileName[strlen(InFileName) - 4], '.') == NULL ))
  28.     {
  29.         /* add the extension if not already there */
  30.         strcat(InFileName, InExtension);
  31.         InFile = open(InFileName, O_RDONLY | O_RAW, 0);
  32.     }
  33.     if ( InFile == -1 )
  34.         returnCode = -1;
  35. Out:
  36.     return(returnCode);
  37. }
  38.  
  39. int OpenOutputFile(extension) /* the file to be IMPORTed into CC:MAIL */
  40. char *extension;
  41. {
  42.     int returnCode = NO_ERROR;
  43.     char *p;
  44.     FILE *tempHandle;
  45.  
  46.     /* make the output (MCB) file in the same directory */
  47.     strcpy(OutFileName,InFileName);
  48. Again:
  49.     p = strrchr(OutFileName,'.');
  50.     if ( p == NULL ) {
  51.         strcat(OutFileName,".");
  52.         goto Again;
  53.     }
  54.     strcpy(p,extension);
  55.  
  56.     tempHandle = fopen(OutFileName, "r");
  57.     if ( tempHandle != NULL ) {
  58.         /* already exists */
  59.         fclose(tempHandle);
  60.         unlink(OutFileName); /* it should do this already if using 0x8301 below */
  61.     }
  62.  
  63.     /* open/create the MCB file for writing */
  64.     OutFile = open(OutFileName, 0x8301, 0);
  65.     if ( OutFile == -1 ) {
  66.         Error(CANNOT_CREATE_OUTPUT);
  67.         goto CantDo;
  68.     }
  69.     goto Out;
  70. CantDo:
  71.     returnCode = CANNOT_CREATE_OUTPUT;
  72. Out:
  73.     return(returnCode);
  74. }
  75.  
  76.  
  77.  
  78.